package com.bosssoft.gateway.authentication.service.factory;

import com.bosssoft.gateway.authentication.pojo.dto.UserDTO;
import com.bosssoft.gateway.authentication.service.LoginClient;
import common.util.CommonResponseUtils;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @className: UserFallbackFactory
 * @description: 实现降级逻辑
 * @author: lanyukai
 * @date: 2024/6/21 10:06
 * @since 1.0
 **/
@Component
public class UserFallbackFactory implements FallbackFactory<LoginClient> {
    /**
     * 调用网关内部的登录方法，进行降级策略
     * @param throwable
     * @return 默认的登录用户，无法登录
     */
    @Override
    public LoginClient create(Throwable throwable) {
        return loginQuery -> CommonResponseUtils.success(new UserDTO(0L, "default", "default", 0L, 0L, 0L, null));
    }
}
